package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.vo.AdminUserExchangeRecordVO;
import com.sc.nft.entity.vo.UserExchangeRecordVo;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.UserExchangeRecord;
import com.sc.nft.mapper.UserExchangeRecordMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * (sc_user_exchange_record)数据DAO
 *
 * @author rdg
 * @since 2022-05-31 17:33:19
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class UserExchangeRecordDao extends ServiceImpl<UserExchangeRecordMapper, UserExchangeRecord> {
  @Resource
 UserExchangeRecordMapper userExchangeRecordMapper;
    public List<UserExchangeRecordVo> getUserExchangeRecord(Long userId) {
        return userExchangeRecordMapper.getUserExchangeRecord(userId);
    }

    public Page<AdminUserExchangeRecordVO> pageUserExchangeRecord(Long userId, Integer typeClassify, Date startDate, Date endDate, int pageNo, int pageSize) {
        return userExchangeRecordMapper.pageUserExchangeRecord(new Page(pageNo,pageSize),userId,typeClassify,startDate,endDate);
    }

    public Integer getByUserIdAndProductId(Long userId, Long productId) {
        LambdaQueryWrapper<UserExchangeRecord>wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(UserExchangeRecord::getUserId,userId);
        wrapper.eq(UserExchangeRecord::getProductInfoId,productId);
        return count(wrapper);
    }
}